//
//  UserAccount.m
//  backpack
//
//  Created by wj on 16/6/8.
//  Copyright © 2016年 wujian. All rights reserved.
//

#import "UserAccount.h"

#define AccountFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@account.data",[[NSUserDefaults standardUserDefaults]objectForKey:@"UserID"]]]

#define LoginAccountFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@Loginaccount.data",[[NSUserDefaults standardUserDefaults]objectForKey:@"UserID"]]]

#define ApplyShopsFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ApplyShops.data",[[NSUserDefaults standardUserDefaults]objectForKey:@"UserID"]]]

#pragma mark - 登录返回绑定状态的数据

@implementation ApplyShops

MJCodingImplementation

/**
 *  用户账号归档
 */
+ (void)saveShop:(ApplyShops *)shop;
{
    // 归档
    [NSKeyedArchiver archiveRootObject:shop toFile:ApplyShopsFilePath];
}

/**
 *  读取用户账号存档
 */
+ (ApplyShops *)shop;
{
    // 读取帐号
    ApplyShops *shop = [NSKeyedUnarchiver unarchiveObjectWithFile:ApplyShopsFilePath];
    
    if (!shop) {
        
        shop = [[ApplyShops alloc] init];
    }
    
    return shop;
}


@end

#pragma mark - 登录返回的数据

@implementation loginUser

MJCodingImplementation

/**
 *  用户账号归档
 */
+ (void)saveUser:(loginUser *)user
{
    // 归档
    [NSKeyedArchiver archiveRootObject:user toFile:LoginAccountFilePath];
}

/**
 *  读取用户账号存档
 */
+ (loginUser *)uesr
{
    // 读取帐号
    loginUser *uesr = [NSKeyedUnarchiver unarchiveObjectWithFile:LoginAccountFilePath];
    
    if (!uesr) {
        
        uesr = [[loginUser alloc] init];
    }
    
    return uesr;
}




@end

@implementation UserAccount

MJCodingImplementation

+ (void)saveAccount:(UserAccount *)account
{
    // 归档
    [NSKeyedArchiver archiveRootObject:account toFile:AccountFilePath];
}

+(UserAccount *)account
{
    // 读取帐号
    UserAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:AccountFilePath];
    
    if (!account) {
        
        account = [[UserAccount alloc] init];
    }
    
    return account;
}

@end
